package shooter;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import shooter.maps.ImageRoutines;

/**
 * Is called once when the game starts. It loads all image files of the game
 * and provides them to all components.
 * 
 * @author MiTaAi07 
 */
public class Images {
	
	public static BufferedImage[] playersRot;
	public static BufferedImage[] playersBlau;
	public static BufferedImage shot;
	public static BufferedImage schnee;
	public static BufferedImage[] images;
	public static BufferedImage[] zahlen;
	public static BufferedImage[] zahlenRot;
	
	/**
	 * The constructor loads all media files.
	 */
	public Images(){
		
		playersRot = new BufferedImage[6];
		for(int i = 0; i < 6; i++){
			try {
				playersRot[i] = ImageIO.read(getClass().getResource(Einstellungen.getShooterImageFolderPath()+"rot"+i+".png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		playersBlau = new BufferedImage[6];
		for(int i = 0; i < 6; i++){
			try {
				playersBlau[i] = ImageIO.read(getClass().getResource(Einstellungen.getShooterImageFolderPath()+"blau"+i+".png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		shot = null;
		try {
			shot = ImageIO.read(getClass().getResource(Einstellungen.getShooterImageFolderPath()+"bullet.png"));
		} catch (IOException e1) {
			System.out.println("Bild nicht geladen");
			e1.printStackTrace();
		}
		
		schnee = null;
		try {
			schnee = ImageIO.read(getClass().getResource(Einstellungen.getShooterImageFolderPath()+"snow.png"));
		} catch (IOException e1) {
			System.out.println("Bild nicht geladen");
			e1.printStackTrace();
		}
		
		images = new BufferedImage[11];
		for(int i = 0; i < 8; i++){
			try {
				images[i] = ImageIO.read(getClass().getResource(Einstellungen.getMapImageFolderPath()+i+".png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
			images[i] = ImageRoutines.optimizeImage(images[i]);
		}
		
		zahlen = new BufferedImage[12];
		
		for(int k = 0;k < 10;k++){
			try
	        {
				zahlen[k] = ImageIO.read(getClass().getResource(Einstellungen.getZahlenFolderPath()+k+".png"));
	        }
			catch (Exception ex){System.out.println("Invalid Image");}
		}		
		try
        {
			zahlen[11] = ImageIO.read(getClass().getResource(Einstellungen.getZahlenFolderPath()+"brake.png"));
        }
		catch (Exception ex){System.out.println("Invalid Image");}
		try
        {
			zahlen[10] = ImageIO.read(getClass().getResource(Einstellungen.getZahlenFolderPath()+"doppelpunkt.png"));
        }
		catch (Exception ex){System.out.println("Invalid Image");}
		
		zahlenRot = new BufferedImage[12];
		
		for(int k = 0;k < 10;k++){
			try
	        {
				zahlenRot[k] = ImageIO.read(getClass().getResource(Einstellungen.getZahlenRotFolderPath()+k+".png"));
	        }
			catch (Exception ex){System.out.println("Invalid Image");}
		}
		try
        {
			zahlenRot[10] = ImageIO.read(getClass().getResource(Einstellungen.getZahlenRotFolderPath()+"doppelpunkt.png"));
        }
		catch (Exception ex){System.out.println("Invalid Image");}
	}
	
}
